<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>畅销型号</title>
    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">

    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>

    <script type="text/javascript" src="/webapp/js/common/jquery.global.settings.js"></script>

    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/webapp/js/common/config.js"></script>


</head>
<body>
     <div class="easyui-container-fluid">
         <div class="easyui-panel" style="border:none;">
             <div class="nav" id="nav"></div>
             <div class="easyui-panel" style="border:none;">
                 <form id="ff">
                     <div style="margin-bottom:10px;">
                     	<span>
                         <label class="item-label">年份：</label>
                         <input type="text" class="easyui-combobox" name="year" id="year" style="width:100px;"/>
                     	</span>
                     	<span id="monthLabel">
	                         <label class="item-label">月份：</label>
	                         <input type="text" class="easyui-combobox" name="month" id="month" style="width:100px;"/></span>
                     	<span id="weekLabel">
	                         <label class="item-label">周数：</label>
	                         <input type="text" class="easyui-combobox" name="week" id="week"  style="width:100px;"/></span>
                         <label class="item-label">品类：</label>
                         <select id="categorySelect" name="categoryCode" class="easyui-combobox" style="width:100px;"></select>
                         <label class="item-label">品牌：</label>
                         <select id="brandSelect" name="brandCode" class="easyui-combobox" style="width:100px;">
                         </select>
                     	<label class="item-label">类型：</label>
		                <select  name="sortType" class="easyui-combobox" id="felx" data-options="panelHeight:'98'" style="width:100px;"  >
		                	<option value="COUNTSORT">量排序</option>
		                	<option value="AMOUNTSORT">额排序</option>
		                	<option value="AVGPRICE">均价</option>
		                </select>
                         <label class="item-label">排名：</label>
                         <input type="text" name="ranking" id="ranking" class="easyui-textbox"value="100" style="width:100px;" />
                         <label class="item-label" style="width: 80px;margin-left: 20px;">数据状态：</label>
                         <select id="comboSyayus" name="comboSyayus" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:80px;" prompt="比较符">
                             <option value="ALL"  selected = "selected" >不限制</option>
                             <option value="COMBO">套餐</option>
                             <option value="NOCOMBO">非套餐</option>
                         </select>
                         <label class="item-label" >商场码：</label>
                         <select id="mallComparer" name="mallComparer" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:50px;" prompt="比较符">
                             <option value="EQUAL"  selected = "selected" >=</option>
                             <option value="NOT_EQUAL"><pre><></pre></option>
                         </select>
                         <input type="text" id="mallCode" name="mallCode" class="easyui-textbox" data-options="
                                                        prompt: '多个用逗号隔开',panelHeight:'150'" style="width:120px;" />
                         <div style="margin-left: 10px">

                             <label class="item-label" >渠道码：</label>
                             <select id="channelComparer" name="channelComparer" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:50px;" prompt="比较符">
                                 <option value="EQUAL"  selected = "selected" >=</option>
                                 <option value="NOT_EQUAL"><pre><></pre></option>
                             </select>
                             <input type="text" id="channelSelect" name="channelCode" class="easyui-textbox" data-options="
                                                        prompt: '多个用逗号隔开',panelHeight:'150'" style="width:120px;"/>
                             <div style="display:inline-block;" id="categorywrapper">
                                 <label class="item-label">规格：</label>
                                 <input type="text" name="propCode" id="propCode" class="easyui-combobox" data-options="panelHeight:'100'" style="width:100px; " />
                                 <!--<input type="text" name="comparator" id="comparator"  class="easyui-combobox" data-options="panelHeight:'150'" style="width:100px;" />-->
                                 <select name="comparator" id="comparator"  class="easyui-combobox" data-options="panelHeight:'150'" style="width:100px;"   >
                                     <option value="EQUAL">=</option>
                                     <option value="GREAT">></option>
                                     <option value="GREAT_EQUAL">>=</option>
                                     <option value="LITTLE"><</option>
                                     <option value="LITTLE_EQUAL"><=</option>
                                     <option value="NOT_EQUAL"><></option>
                                     <option value="CONTAIN">包含</option>
                                 </select>
                                 <div style="display: inline-block" id="metadatavalue" >
                                 </div>
                                 <label class="item-label" style="width: 100px;pxmargin-left: 20px;">拼抖快型号：</label>
                                 <input id="isExcludePdkSpecial" class="easyui-switchbutton" checked style="width:90px;height:30px;" onText="排除" offText="不排除"  >

                             </div>
                             <a href="javascript:void(0);" style="margin-left:40px;width:80px;" class="easyui-linkbutton c8" onclick="searchBy()">查询</a>
                         </div>

                     </div>
                     <!--<div style="margin-bottom:10px;margin-left: 10px;text-align:left;">-->
                     	<!--<span id="totalInfo" style="margin-right:10px;font-weight: bold;font-size: 16px;"></span>-->
                     <!--</div>-->
                 </form>
             </div>
             <div class="table-wrapper" >
                 <table id="datagrid" class="easyui-datagrid" data-options="fitColumns:true,scrollbarSize:0" style="max-height: 708px;">
                     <thead>
                        <tr>
                            <th data-options="field:'brandName',align:'center'" width="120" formatter="formatBrand" >品牌</th>
                            <th data-options="field:'modelName',align:'center'" width="150"formatter="formatModel">型号</th>
                            <th data-options="field:'onquantitative.top',align:'center'" width="60" formatter="formatQTop">本期排名</th>
                            <th data-options="field:'quantitative.top',align:'center'" width="60" formatter="formatOTop" >上期排名</th>
                            <th data-options="field:'onquantitative.cshares',align:'center'" width="100" formatter="formatOcshares">本期量份额</th>
                            <th data-options="field:'quantitative.cshares',align:'center'" width="100" formatter="formatQcshares">上期量份额</th>
                            <th data-options="field:'onquantitative.bqct',align:'center'" width="100" formatter="formbqct">本期量/额</th>
                            <th data-options="field:'onquantitative.sqct',align:'center'" width="100" formatter="formsqct">上期量/额</th>
                            <th data-options="field:'onquantitative.tshares',align:'center'" width="100" formatter="formatOtshares">本期额份额</th>
                            <th data-options="field:'quantitative.tshares',align:'center'" width="100" formatter="formatQtshares">上期额份额</th>
                            <th data-options="field:'onquantitative.avgPrice',align:'center'" width="100" formatter="formatOavgPrice" >本期均价</th>
                            <th data-options="field:'quantitative.avgPrice',align:'center'" width="100" formatter="formatQavgPrice">上期均价</th>
                        </tr>
                     </thead>
                 </table>
             </div>
         </div>
     </div>
     <script type="text/javascript">
         var checkedItems = "AMOUNTSORT";
         $(function(){
             setNav();
             initUserCategorySelect("categorySelect",function (code) {
                 initModelSearchSelect("propCode","metadatavalue",code);
                 initBrandSelectC("brandSelect",null,null,code);
             });

             initProvinceSelect("provinceSelect", provinceChange);
             initMonthWeek("monthLabel","weekLabel");
             $("#datagrid").datagrid({
                 // pagination:true,
                 rownumbers:true
             });
             aRecords("畅销型号","/webapp/pages/product/audit/modeltop")
         });
         function provinceChange(provinceCode){
        	initCitySelect("citySelect", provinceCode);
   			$.ajax({
   		        url:config.url+'/dictionary/getCityByProvince/'+provinceCode,
   		        type:"get",
   		        xhrFields:{withCredentials:true},
   		        success:function (data) {
   		            if(data){
   		                $(data).map(function(index,item){
   		                    item['text'] = item.name;
   		                });
   		                data.unshift({"text":"-请选择-","code":""});
   		                $("#citySelect").combobox({
   		                    "textFiled":"text",
   		                    "valueField":"code",
   		                    "data":data
   		                });
   		            }
   		        },
   		        error:function(XMLHttpRequest,textStatus,errorThrown){
   		        }
   		    })
         }
         
         function searchBy(){
        	 if(!$('#categorySelect').combobox('getValue')){
        		 alert('请选择品类');
        		 return;
        	 }
        	 if(!$('#ranking').textbox('getValue')){
        		 alert('请填写排名');
        		 return;
        	 }
             var data = getFormData(document.getElementById("ff"));
             data.reportType=window.parent.workMode.toUpperCase();
             data.isExcludePdkSpecial = $("#isExcludePdkSpecial").switchbutton("options").checked ? 'true' : 'false';
             if(data.sortType =="AVGPRICE"){
                 window.location.href = "/webapp/pages/product/audit/modelAvgprice.html";
             }
             data.mallCode=$("#mallCode").val();
             $.ajax({
                  url:config.url + "/modelTop/data",
                  type:"GET",
                  data:transfer(data),

                 dataType:'json',
                  xhrFields:{withCredentials:true},
                  beforeSend:function () {
                      $.messager.progress({
                          title:"请稍等",
                          interval:50,
                          text:"数据加载中..."
                      });
                    },
                  success:function(data){
                	  $.messager.progress("close");
                      if (data.code && data.code == 515) {
                          $.messager.alert("提示", data.msg, "error");
                          return;
                      }
                      checkedItems=$("#felx").combobox("getValue");
                      var totalInfo = '';
                      // console.log(Object.keys(data.data))
                      if(null != data){
                          $("#datagrid").datagrid("loadData",data);
                	  $('#totalInfo').html(totalInfo);
                      }else {
                          $('#totalInfo').html(totalInfo);
                          $("#datagrid").datagrid({data: []}).datagrid("getPager");
                          $.messager.progress("close");
                      }
                  },
                  error:function(data){
                     console.log(data);
                     $.messager.progress("close");
                  }
              });
          }
        
        function formatBrand(val, row) {
 			return row.brandName + '(' + row.brandCode + ')';
 		}
 		function formatModel(val, row) {
 			return row.modelName + '(' + row.modelCode + ')';
 		}

         function formatQTop(val, row){
             if(row.onquantitative !=null && row.onquantitative.top !=null){
                 return row.onquantitative.top;
             }else{
                 return "--";
             }
             // return row.onquantitative.top;
         }
         function formatOTop(val, row){
             if(row.quantitative !=null && row.quantitative.top !=null){
                 return row.quantitative.top;
             }else{
                 return "--";
             }

         }
		function formatOcshares(val, row) {
            if(row.onquantitative !=null && row.onquantitative.cshares !=null){
                return row.onquantitative.cshares + '%';
            }else{
                return "--";
            }

		}
		function formbqct(val, row) {
            if(row.onquantitative !=null && checkedItems != "AVGPRICE"){
                if(row.onquantitative.count !=null && checkedItems == "COUNTSORT"){
                    return row.onquantitative.count;
                }else if(row.onquantitative.total !=null && checkedItems == "AMOUNTSORT"){
                    return row.onquantitative.total;
                }else{
                    return "--";
                }
            }else{
                return "--";
            }
		}
         function formsqct(val, row) {
             if(row.quantitative !=null && checkedItems != "AVGPRICE"){
                 if(row.quantitative.count !=null && checkedItems == "COUNTSORT"){
                     return row.quantitative.count;
                 }else if(row.quantitative.total !=null && checkedItems == "AMOUNTSORT"){
                     return row.quantitative.total;
                 }else{
                     return "--";
                 }
             }else{
                 return "--";
             }
         }
		function formatOtshares(val, row) {
            if(row.onquantitative !=null && row.onquantitative.tshares !=null){
                return row.onquantitative.tshares + '%';
            }else{
                return "--";
            }
		}
		function formatQcshares(val, row) {
            if(row.quantitative !=null && row.quantitative.cshares !=null){
                return row.quantitative.cshares + '%';
            }else{
                return "--";
            }

		}
		function formatQtshares(val, row) {
            if(row.quantitative !=null && row.quantitative.tshares !=null){
                return row.quantitative.tshares + '%';
            }else{
                return "--";
            }
		}
		function formatOavgPrice(val, row) {
            if(row.onquantitative !=null && row.onquantitative.avgPrice !=null){
                return row.onquantitative.avgPrice ;
            }else{
                return "--";
            }
		}
		function formatQavgPrice(val, row) {
            if(row.quantitative !=null && row.quantitative.avgPrice !=null){
                return row.quantitative.avgPrice ;
            }else{
                return "--";
            }
			// return row.quantitative.avgPrice + '%';
		}
		function style(text, flag){
			if('yes'==flag){
				return '<span style="font-size: 14px;font-weight: bold;color: red;">' + text + '</span>';
			}else if('no'==flag){
				return '<span style="font-size: 14px;font-weight: bold;color: green;">' + text + '</span>';
			}
			return text;
		}


         function initChannelSelectshare(channelSelectId, mallSelectId, initCallback){
             var dtd = $.Deferred();
             $.ajax({
                 url:config.url +"/channel/getAll",
                 type:"get",
                 xhrFields:{withCredentials:true},
                 success:function (data) {
                     if(data){
                         data.unshift({"name":"-请选择-","code":"-请选择-","selected":true});
                         $("#"+channelSelectId).combobox({
                             "textField":"code",
                             "valueField":"code",
                             "panelHeight":"150",
                             "data":data
                         });
                         dtd.resolve();
                         // 回调函数
                         if(typeof initCallback === "function"){
                             if(data.length>=2){
                                 $("#"+channelSelectId).combobox('select', data[1]['code']);
                             }
                             initCallback();
                         }
                     }
                 },
                 error:function(XMLHttpRequest,textStatus,errorThrown){
                     dtd.reject();
                 }
             });
             return dtd.promise();
         }
         $("#ff").keydown(function (event) {
             var e = event || window.event;
             var keyCode = e.keyCode || e.which;
             if(keyCode=="13"){
                 searchBy();
             }
         });
     </script>
</body>
</html>